<?php
/**
 * VgotFaster PHP Framework
 *
 * Text Helpers
 *
 * @package VgotFaster
 * @author pader
 * @copyright Copyright (c) 2009-2010, VGOT.NET
 * @link http://www.vgot.net/ http://vgotfaster.googlecode.com
 * @filesource
 */

/**
 * Cut String
 *
 * You can use to chinese string, but not UTF-8 encode
 *
 * @param string $str
 * @param int $cutleng
 * @param string $ct
 * @return
 */
if(!function_exists('cutstr'))
{
	function cutstr($str,$cutleng,$ct='..') {
		$strleng = strlen($str);
		if($cutleng > $strleng) return $str;
		$notchinanum = 0;
		for($i=0;$i<$cutleng;$i++) {
			if(ord(substr($str,$i,1))<=128) $notchinanum++;
		}
		if(($cutleng % 2 == 1) and ($notchinanum % 2 == 0)) $cutleng++;
		if(($cutleng % 2 == 0) and ($notchinanum % 2 == 1)) $cutleng++;
		return substr($str,0,$cutleng).$ct;
	}
}

/**
 * Obtain The Text Inside The HTML
 *
 * @param string $str HTML
 * @return
 */
if(!function_exists('html2text'))
{
	function html2text($str) {
		$str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU",'',$str);
		$str = str_replace(array('<br />','<br>','<br/>'), "\n", $str);
		$str = strip_tags($str);
		return $str;
	}
}

?>